package com.keyinong.caizhengting.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.keyinong.caizhengting.R;
import com.keyinong.caizhengting.tools.HttpTools;
import com.keyinong.caizhengting.tools.ImageUtils;
import com.keyinong.caizhengting.entity.XiaotieshiEntity;

import java.util.ArrayList;

/**
 * 小贴士
 */

public class XiaotieshiAdapter extends BaseAdapter {
    Context context;
    ArrayList<XiaotieshiEntity> xiaotieshiList;
    HttpTools httpTools = null;

    public XiaotieshiAdapter(Context context, ArrayList<XiaotieshiEntity> xiaotieshiList) {
        super();
        this.context = context;
        this.xiaotieshiList = xiaotieshiList;
    }

    @Override
    public int getCount() {
        // TODO Auto-generated method stub
        return xiaotieshiList.size();
    }

    @Override
    public Object getItem(int position) {
        // TODO Auto-generated method stub
        return xiaotieshiList.get(position);
    }

    @Override
    public long getItemId(int position) {
        // TODO Auto-generated method stub
        return 0;
    }

    @Override
    public View getView(int position, View view, ViewGroup parent) {
        final ViewHandle handle;
        if (view == null) {
            handle = new ViewHandle();
            view = LayoutInflater.from(context).inflate(R.layout.item_xiaotieshi, null);
            handle.tv_time = (TextView) view.findViewById(R.id.tv_time);
            handle.tv_brief = (TextView) view.findViewById(R.id.tv_brief);
            handle.iv_pic = (ImageView) view.findViewById(R.id.iv_pic);
            view.setTag(handle);
        } else {
            handle = (ViewHandle) view.getTag();
        }
        handle.tv_brief.setText(xiaotieshiList.get(position).getBrief());
        handle.tv_time.setText(xiaotieshiList.get(position).getShow_time());
        ImageUtils.displayImage(context,
                (xiaotieshiList.get(position).getPic() + "?imageView2/1/w/360/h/300").replace("w/60", "w/120"),
                handle.iv_pic, R.drawable.wupian1);
        return view;
    }

    class ViewHandle {
        /**
         * 图片
         */
        ImageView iv_pic;
        /**
         * 标题
         */
        TextView tv_brief;
        /**
         * 时间
         */
        TextView tv_time;
    }
}
